﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Reflection;

namespace Apollo.Configuration
{
    public class ApolloElement : ConfigurationElement
    {
        [ConfigurationProperty("clientName", IsRequired = true)]
        public string ClientName {
            get { return (string)this["clientName"]; }
            set { this["clientName"] = value; }
        } 

        [ConfigurationProperty("logoPath", IsRequired = false)]
        public string LogoPath
        {
            get { return (string)this["logoPath"]; }
            set { this["logoPath"] = value; }
        }

        [ConfigurationProperty("ldap", IsRequired = false)]
        public LDAPElement LDAP
        {
            get { return (LDAPElement)this["ldap"]; }
            set { this["ldap"] = value; }
        } 

        [ConfigurationProperty("userType", IsRequired = false)]
        public string UserTypeString
        {
            get { return (string)this["userType"]; }
            set { this["userType"] = value; }
        }

        public Type UserType {
            get {
                if (string.IsNullOrEmpty(this.UserTypeString))
                    return null;

                return Type.GetType(this.UserTypeString);
            }
        }

        private string version;
        public string Version {
            get {
                if (version == null) {
                    Version v = Assembly.GetAssembly(typeof(ApolloElement)).GetName().Version;
                    version = string.Format("{0}.{1}.{2}", v.Major, v.Minor, v.Build);
                }

                return version;
            }
        }

        [ConfigurationProperty("sqlTemplates")]
        public SqlTemplates SqlTemplates {
            get { return (SqlTemplates)this["sqlTemplates"] ?? new SqlTemplates(); }
            //set { this["sqlTemplates"] = value; }
        }
    }
}
